package com.wangyk.rabbitmqcommon.model.jpaproject;

import lombok.Data;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.Fetch;

import javax.persistence.*;

import java.util.List;

import static javax.persistence.GenerationType.IDENTITY;

@Data//省去get(),set()方法
@Entity//映射数据库中的实体类
@DynamicInsert//添加的时候，值为空的属性则会省略
@DynamicUpdate//修改的时候，值为空的属性则不会修改
@Table(name="category")//表名
public class Category
{
    //种类的Id
    @Id
    //主键自增策略
    @GeneratedValue(strategy = IDENTITY)
    private Integer categoryId;

    //种类的名称
    private String categoryName;

    @OneToMany(targetEntity = ProductInfo.class,fetch = FetchType.LAZY)
    @JoinColumn(name = "categoryId")//指2表连接的关键字
    private List<ProductInfo> productInfos;
}
